import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:sudoku/util/app_util.dart';
import 'package:sudoku/widget/MenuButton.dart';
import '../util/widget_util.dart';

class PauseDialog extends StatelessWidget {
  final int countdownCount;

  PauseDialog(this.countdownCount);

  @override
  Widget build(BuildContext context) {
    return Material(
        color: Colors.transparent,
        child: ClipRRect(
            //切割很重要
            child: Stack(
          clipBehavior: Clip.hardEdge,
          alignment: Alignment.center,
          children: <Widget>[
            Positioned.fill(
              child: BackdropFilter(
                filter: ImageFilter.blur(sigmaX: 10, sigmaY: 10), //可以看源码
                child: Container(
                  decoration: BoxDecoration(
                    color: const Color.fromRGBO(225, 225, 225, 1)
                        .withOpacity(0.06),
                  ),
                ),
              ),
            ),
            Container(
              width: Get.width * 0.8,
              height: 200,
              decoration: BoxDecoration(
                  gradient: dialogGradient,
                  borderRadius: BorderRadius.circular(15)),
              child: Column(
                mainAxisAlignment: MainAxisAlignment.start,
                children: [
                  const SizedBox(
                    height: 15,
                  ),
                  const Text(
                    "已暂停",
                    style: TextStyle(
                        color: Colors.white,
                        fontFamily: "Han",
                        fontSize: 30,
                        fontWeight: FontWeight.bold),
                  ),
                  const SizedBox(
                    height: 15,
                  ),
                  Text(
                    "当前用时：${durationStr(countdownCount)}",
                    style:const TextStyle(
                        color: Colors.white, fontSize: 20, fontFamily: "Han"),
                  ),
                  const SizedBox(
                    height: 25,
                  ),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceAround,
                    children: [
                      MenuButton(
                          onPressed: () {
                            Get.back(result: 1);
                          },
                          title: "返回首页"),
                      MenuButton(
                          onPressed: () {
                            Get.back(result: 2);
                          },
                          title: "继续"),
                    ],
                  )
                ],
              ),
            ),
          ],
        )));
  }
}

Future showPauseDialog(int countdownCount) {
  return showDialog(
      useSafeArea: false,
      context: Get.context!,
      builder: (context) {
        return PauseDialog(countdownCount);
      });
}
